﻿//解决ajax跨xxx.checkoo.com多个域的问题。
//document.domain = "checkoo.com";



var Ka=navigator.userAgent.toLowerCase();
var rt=Ka.indexOf("opera")!=-1;
var r=Ka.indexOf("msie")!=-1&&(document.all&&!rt);
var fG=r&&Ka.indexOf("msie 5")!=-1;
var FG=r&&Ka.indexOf("msie 6")!=-1;
var GG=r&&Ka.indexOf("msie 7")!=-1;
var gG=Ka.indexOf("konqueror")!=-1;
var O=Ka.indexOf("safari")!=-1||gG;
var eG=Ka.indexOf("camino")!=-1;
var X=!r&&(!O&&(Ka.indexOf("mozilla")!=-1||rt));
var hG=Ka.indexOf("macintosh")!=-1;
var HG=Ka.indexOf("linux")!=-1;
var iG=Ka.indexOf("windows nt 5.1")!=-1||Ka.indexOf("windows xp")!=-1;
var dG=Ka.indexOf("windows nt 5.0")!=-1||Ka.indexOf("windows 2000")!=-1;
var tG=iG||dG;

//alert("22:"+GG);

//var SITE_URL = "http://i.checkoo.com";
//var SITE_URL = "http://"+location.hostname;
var SITE_URL = "http://"+location.host;
//ajax xmlhttprequest
function newXMLHttpRequest() {
  var xmlreq = false;
  if(GG){
	  xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
  }else if (window.ActiveXObject) {
    try {
      xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e1) {
      try {
        xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
      }
    }
  }
  else if (window.XMLHttpRequest) {
	//alert("31");
    xmlreq = new XMLHttpRequest();
  }
  return xmlreq;
}

//send ajax get request
function doGet (url) {
	var xmlreq = newXMLHttpRequest();
	var result = "";
	//msie
	if (r){
		xmlreq.onreadyStatechange=function() {
				if (xmlreq.readyState == 4){
						if (xmlreq.status == 200){
								result = xmlreq.responseText;
						}//200
						else{
							result = "false";
						}
				}//
			}
	}
	//mozilla
	else if (X){
		xmlreq.onload=function() {
			result = xmlreq.responseText;
		}
	}
	else {
		result = "您的浏览器不支持ajax";
	}
	xmlreq.open("GET",url,false);
	xmlreq.send(null);

	return result;
}

//send ajax post  request 
function doPost (url , data) {
	//alert(url+"           "+data);
	var xmlreq = newXMLHttpRequest();
	var result = "";
	//msie
	//alert("line:83:r="+r+":X="+X);
	if (r){
		//alert("line:84:"+(typeof(xmlreq))+":");
		xmlreq.onreadyStatechange=function() {
		//alert("line:85:"+xmlreq.readyState+":"+xmlreq.status+":"+xmlreq.responseText);
			if (xmlreq.readyState == 4){
				//alert("line:88:");
				if (xmlreq.status == 200){
					//alert("line:89:");
					result = xmlreq.responseText;
				}//200
				else{
					//alert("line:90:");
					result = "false"
				}
			}//readyStat != 4
			else{
				//alert("line:97:"+xmlreq.readyState+":"+xmlreq.status+":"+xmlreq.responseText);
				result = "false";
			}
		}//end if stateChange
		//alert("line:104:");
		//result = "服务器错误："+xmlreq.status;
	}//end if ie
	//mozilla
	else if (X){
		//alert("line:103:"+xmlreq.readyState+":"+xmlreq.status+":");
		xmlreq.onload=function() {
			result = xmlreq.responseText;
			//alert("line:106:"+xmlreq.readyState+":"+xmlreq.status+":"+result);
		}
	}
	else {
		result = "false";
	}

	xmlreq.open("POST",url,false);
	xmlreq.setRequestHeader("Content-Length",data.length);    
	xmlreq.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
	xmlreq.send(data);

	return result;
}
